package com.mys.maggie.redis.api.config;

import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;


/**
 * @since 2020/8/31
 */
@Data
@ConfigurationProperties(prefix = MagRedisProperties.MAG_REDIS_PREFIX)
@ConditionalOnProperty(prefix = "maggie-redis", name = {"enabled"} , matchIfMissing = true)
public class MagRedisProperties {
  static final String MAG_REDIS_PREFIX = "maggie-redis";

  /**
   * 应用名称
   */
  private String applicationName;


  /**
   *   最大活跃数
   */
  private Integer maxActive = 100;

  /**
   *   最长等待
   */
  private Integer maxWait = 5000;

  /**
   *   最大空闲数
   */
  private Integer maxIdle = 30;

  /**
   *   最小空闲数
   */
  private Integer minIdle = 10;

  /**
   *   集群组
   */
  private List<Cluster> clusters;

  /**
   *   当前jar的版本
   */
  private String version;

  /**
   * 连接redis的方式 0:lettuce 1:jedis
   */
  private Integer clientType=0 ;

  /**
   * 读取超时
   */
  private Integer readTimeOut;
  /**
   * key的序列化方式 -> SerializerTypeEnum
   */
  private Integer keySerializer;
  /**
   * value的序列化方式 -> SerializerTypeEnum
   */
  private Integer valueSerializer;
  /**
   * hashKey的序列化方式 -> SerializerTypeEnum
   */
  private Integer hashKeySerializer;
  /**
   * hashValue的序列化方式 -> SerializerTypeEnum
   */
  private Integer hashValueSerializer;

  @Data
  public static class Cluster {
    private String name;
    private String password;
    private Integer maxActive;
    private Integer maxWait;
    private Integer maxIdle;
    private Integer minIdle;
    private Integer readTimeOut;
    private Boolean standalone = false;//true 是单机，false 是集群。 默认集群false
    private Integer clientType =0 ;
    private List<String> nodes;
    private Integer keySerializer; //类型枚举对应 -> SerializerTypeEnum
    private Integer valueSerializer;//类型枚举对应 -> SerializerTypeEnum
    private Integer hashKeySerializer;//类型枚举对应 -> SerializerTypeEnum
    private Integer hashValueSerializer;//类型枚举对应 -> SerializerTypeEnum

  }


}
